<?php
/*
 * [cut_piece description]
 * @param  [字符串] $str     [只适合纯中文字符串]
 * @param  [即将转换类型] $charset ["ASCII", "UTF-8", "GB2312", "GBK", "BIG5"]
 * @return [已转换字符串] $arra      [已转换字符串]
 */
public function cut_piece($str,$charset){
	$strlen=mb_strlen($str,$charset);
/*	$encoding=mb_detect_encoding($str,array("ASCII", "UTF-8", "GB2312", "GBK", "BIG5"));
	echo "转换前".$encoding."<br/>";
	if($encoding!="UTF-8") $str=mb_convert_encoding($str,'UTF-8',$encoding);
	$encoding=mb_detect_encoding($str,array("ASCII", "UTF-8", "GB2312", "GBK", "BIG5");)
	echo "转换后".$encoding."<br/>";
	*/
	for($i=0;$i<$strlen;$i++){
		//if($i=0){
		//	$arra=mb_substr($str,$i,$j,$charset);
		//}else{
			$arra[$i]=mb_substr($str,$i,1,$charset);
		//}
	}
	return $arra;
	
}


/**
 * [getNormalName description]
 * @param  string $str     [description]
 * @param  [type] $charset [description]
 * @param  int    $time    [description]
 * @return [type]          [description]
 */
public function getNormalName(string $str,$charset,int $time){
	$cut_arra  = "";
	$cut_array = cut_piece($str,$charset);
	$cut_len   = count($cut_array);
	//根据time取出多少个字
	for($i=0;$i<$time;$i++){
		$rand=rand(0,$cut_len-1);
		$cut_arra=$cut_arra.$cut_array[$rand];
	}
	return $cutarra;
	
}
/*
 * [getNormalName2 description]
 * @param  [type] $cut_array [description]
 * @param  [type] $time      [description]
 * @return [type]            [description]
 */
/**
 * [getNormalName2 description]
 * @param  [type] $cut_array [description]
 * @param  [type] $time      [description]
 * @return [type]            [description]
 */
public function getNormalName2($cut_array,$time){
	$cut_arra = "";
	$cut_len  = count($cut_array);
	//根据time取出多少个字
	for($i=0;$i<$time;$i++){
		$rand=rand(0,$cut_len-1);
		$cut_arra=$cut_arra.$cut_array[$rand];
	}
	return $cut_arra;
	/**
	 * @return [数组] [返回一个数组]
	 */
} 
/**
 * [getRandomName 获取随机汉字]
 * @return [汉字] [字符]
 */
public function getRandomName(){
	$unidec  =rand(19968,40869);
	$unichr  ='&#'.$unidec.';';
	$zhcnchr =mb_convert_encoding($unichr,"UTF8","HTML-ENTITIES");
	return $zhcnchr;
}
/**
 * [getCut description]
 * @param  [type] $str   [description]
 * @param  [type] $times [description]
 * @return [type]        [description]
 */
public function getCut($str,$times){
	$len=count($str);
	$arr="";
	for($i=0;$i<$times;$i++){
		$s=rand(0,$len-1);
		$arr=$arr.$str[$s];
		//echo $arr.' 1<br/>';
	}
	//echo $arr.'2<br/>';
	return $arr;
}
?>